Ext.define('SKJF.view.MASTER.v_mstbarang', {
	extend: 'Ext.grid.Panel',
	requires: ['SKJF.store.s_mstbarang'],
	
	title		: 'mstbarang',
	itemId		: 'Listmstbarang',
	alias       : 'widget.Listmstbarang',
	store 		: 's_mstbarang',
	columnLines : true,
	frame		: false,
	
	margin		: 0,
	selectedIndex : -1,
	
	initComponent: function(){
		var me = this;
		
		var docktool = Ext.create('Ext.toolbar.Paging', {
			store: 's_mstbarang',
			dock: 'bottom',
			displayInfo: true
		});
		
		this.columns = [
			{
				header: 'KODE_BARANG',flex:1,
				dataIndex: 'KODE_BARANG'
			},{
				header: 'NAMA_BARANG',filterable: true,flex:1,
				dataIndex: 'NAMA_BARANG'
			},{
				header: 'JENIS_BARANG',filterable: true,flex:1,
				dataIndex: 'JENIS_BARANG'
			},{
				header: 'SATUAN',flex:1,
				dataIndex: 'SATUAN'
			},{
				header: 'HSCODE',flex:1,
				dataIndex: 'HSCODE'
			},{
				header: 'STOCK',filterable: true,flex:1,
				dataIndex: 'STOCK',
				align: 'right'
			}];
		this.features = [{
			ftype: 'filters',
			autoReload: true, //don't reload automatically
			encode: true, // json encode the filter query
			local: false
		}];
		this.dockedItems = [
			Ext.create('Ext.toolbar.Toolbar', {
				items: [{
					xtype: 'fieldcontainer',
					layout: 'hbox',
					defaultType: 'button',
					items: [{
						text	: 'Add',
						iconCls	: 'icon-add',
						action	: 'create'
					}, {
						xtype: 'splitter'
					}, {
						itemId	: 'btndelete',
						text	: 'Delete',
						iconCls	: 'icon-remove',
						action	: 'delete',
						disabled: true
					}]
				}, '-', {
					xtype: 'fieldcontainer',
					layout: 'hbox',
					defaultType: 'button',
					items: [{
						text	: 'Cetak',
						iconCls	: 'icon-print',
						action	: 'print'
					}]
				}]
			}),docktool
		];
		
		docktool.add([{
				text: 'Clear Filter Data',
				handler: function () {
					me.filters.clearFilters();
				} 
			}
		]);
		
		this.callParent(arguments);
		
		this.on('itemclick', this.gridSelection);
		this.getView().on('refresh', this.refreshSelection, this);
	},	
	
	gridSelection: function(me, record, item, index, e, eOpts){
		//me.getSelectionModel().select(index);
		this.selectedIndex = index;
		this.getView().saveScrollState();
	},
	
	refreshSelection: function() {
        this.getSelectionModel().select(this.selectedIndex);   /*Ext.defer(this.setScrollTop, 30, this, [this.getView().scrollState.top]);*/
    }

});